﻿using System;
using System.Diagnostics.Contracts;

namespace OpenCube.Nbt.Mapping.Converters
{
	/// <summary>
	/// Creates converter for build-in type conversions
	/// </summary>
	[ContractClass(typeof(BuildInConverterFactoryContract))]
	public interface IBuildInConverterFactory
	{
		/// <summary>
		/// Creates a type converter that can convert from/to the given type.
		/// </summary>
		/// <param name="modelType">The type to convert from/to.</param>
		/// <returns>The converter that converts the requested type.</returns>
		/// <remarks>
		/// Build-In converters are limited to one unique model type. 
		/// You cannot - for example - map string to two different nbt types.
		/// This limit is there because when mapping from Model to NBT, the target NBT structure and types are unknown.
		/// </remarks>
		INbtTypeConverter Create(Type modelType);
	}

	[ContractClassFor(typeof(IBuildInConverterFactory))]
	abstract class BuildInConverterFactoryContract
		: IBuildInConverterFactory
	{
		INbtTypeConverter IBuildInConverterFactory.Create(Type modelType)
		{
			Contract.Requires<ArgumentNullException>(modelType != null);
			Contract.Ensures(Contract.Result<INbtTypeConverter>() != null);

			throw new NotImplementedException();
		}
	}
}